package com.sf.rbac.util;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {
    public static final Integer SUCCESS_CODE =200;
    public static final String SUCCESS_STATUS ="success";
    public static final String SUCCESS_MSG ="操作成功";

    public static final Integer FAIL_CODE =500;
    public static final String FAIL_STATUS ="fail";
    public static final String FAIL_MSG ="操作失败";

    //返回状态码 200 表示成功，500表示失败，401表示认证失败，403表示没有权限
    private Integer code;
    //给前端提示信息  操作成功或者失败  认证失败  没有权限
    private String msg;
    // 如果是成功Status=success,如果失败fail
    private String status;
    //后端返回给前端的数据
    private Object data;

    public static JsonResult success(){
        return new JsonResult(SUCCESS_CODE,SUCCESS_MSG,SUCCESS_STATUS,null);
    }
    public static JsonResult success(Object data){
        return new JsonResult(SUCCESS_CODE,SUCCESS_MSG,SUCCESS_STATUS,data);
    }
    public static JsonResult success(String msg,Object data){
        return new JsonResult(SUCCESS_CODE,msg,SUCCESS_STATUS,data);
    }


    public static JsonResult fail(){
        return new JsonResult(FAIL_CODE,FAIL_MSG,FAIL_STATUS,null);
    }
    public static JsonResult fail(Object data){
        return new JsonResult(FAIL_CODE,FAIL_MSG,FAIL_STATUS,data);
    }
    public static JsonResult fail(String msg,Object data){
        return new JsonResult(FAIL_CODE,msg,FAIL_STATUS,data);
    }
}
